package com.util;

public class CodeMsg {
    private int code;
    private String msg;

    // 通用成功码
    public static CodeMsg SUCCESS = new CodeMsg(0, "success");

    // 商品模块
    public static CodeMsg GOODS_NOT_EXIST = new CodeMsg(500300, "商品不存在");

    // 订单模块
    public static CodeMsg ORDER_NOT_EXIST = new CodeMsg(500400, "订单不存在");

    // 评论模块
    public static CodeMsg COMMENT_ADD_ERROR = new CodeMsg(500500, "评论添加失败");
    public static CodeMsg COMMENT_CONTENT_EMPTY = new CodeMsg(500501, "评论内容不能为空");
    public static CodeMsg PARENT_COMMENT_NOT_EXIST = new CodeMsg(500502, "回复的评论不存在");
    public static CodeMsg REPLY_ADD_ERROR = new CodeMsg(500503, "回复发表失败");

    // 举报模块
    public static CodeMsg REPORT_ADD_ERROR = new CodeMsg(500600, "举报提交失败");
    public static CodeMsg REPORT_REASON_EMPTY = new CodeMsg(500601, "举报理由不能为空");


    public CodeMsg(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /**
     * 返回一个带参数的 CodeMsg
     * @param args 填充到消息字符串中的参数
     * @return 新的 CodeMsg 实例，其消息包含填充的参数
     */
    public CodeMsg fillArgs(Object... args) {
        int code = this.code; // 使用当前实例的code
        String message = String.format(this.msg, args); // 使用当前实例的msg格式化字符串
        return new CodeMsg(code, message);
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    @Override
    public String toString() {
        return "CodeMsg [code=" + code + ", msg=" + msg + "]";
    }
} 